package com.shujia.mllib

import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.Vectors

object Demo2Type {
  def main(args: Array[String]): Unit = {

    //1、稠密向量,向量中只能是double类型额数据
    val dense: linalg.Vector = Vectors.dense(1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4)
    println(dense)

    //2、稀疏向量
    //稀疏向量只记录有值的位置

    val sparse: linalg.Vector = Vectors.sparse(14, Array(0, 11, 12, 13), Array(1.0, 2.0, 3.0, 4.0))
    println(sparse)

    //稠密向量和稀疏向量可以相互转换
    println(sparse.toDense)

    //稠密向量在0值少时占用空间小
    //稀疏向量在0值比较多是占用空间小
  }

}
